package com.example.wallpaperapp.base;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
public abstract class BaseFragment extends Fragment implements View.OnClickListener{
    private View view;
    protected final String TAG = this.getClass().getSimpleName();
    public Context mContext;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (view==null){
            view = inflater.inflate(getLayoutId(), container, false);
            initView(view);
            initData(mContext);
        }
        return view;
    }
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mContext = context;
    }
    //控件初始化
    protected abstract void initView(View view);
    //获取布局ID
    protected abstract int getLayoutId();
    // 数据初始化操作
    protected abstract void initData(Context context);
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        //加载数据
        prepareFetchData();
    }
    private void prepareFetchData() {
        //prepareFetchData(false);

    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        this.view = null;
    }


}
